import java.util.*;

class Team {
    String name;              // 队名
    int played;               // 已比赛场数
    int won;                  // 赢的场数
    int drawn;                // 平的场数
    int lost;                 // 负的场数
    int goalsFor;             // 进球数
    int goalsAgainst;         // 失球数
    int points;               // 积分

    // 构造函数
    public Team(String name) {
        this.name = name;
        this.played = 0;
        this.won = 0;
        this.drawn = 0;
        this.lost = 0;
        this.goalsFor = 0;
        this.goalsAgainst = 0;
        this.points = 0;
    }

    // 更新比赛结果
    public void updateStats(int goalsFor, int goalsAgainst) {
        this.played++;
        this.goalsFor += goalsFor;
        this.goalsAgainst += goalsAgainst;

        if (goalsFor > goalsAgainst) {
            this.won++;
            this.points += 3; // 胜一场得3分
        } else if (goalsFor < goalsAgainst) {
            this.lost++;
        } else {
            this.drawn++;
            this.points += 1; // 平局得1分
        }
    }

    // 计算净胜球
    public int goalDifference() {
        return this.goalsFor - this.goalsAgainst;
    }

    // 输出队伍信息
    public void printStats() {
        System.out.printf("%-15s %3d %3d %3d %3d %3d %3d %3d\n", 
            name, played, won, drawn, lost, goalsFor, goalsAgainst, points);
    }
}

class League {
    private List<Team> teams;  // 用于存储所有的队伍

    public League() {
        teams = new ArrayList<>();
    }

    // 添加队伍
    public void addTeam(String name) {
        teams.add(new Team(name));
    }

    // 根据队伍名获取队伍对象
    public Team getTeam(String name) {
        for (Team team : teams) {
            if (team.name.equals(name)) {
                return team;
            }
        }
        return null; // 如果没有找到返回 null
    }

    // 处理比赛结果并更新数据
    public void processMatch(String homeTeam, String awayTeam, int homeGoals, int awayGoals) {
        Team home = getTeam(homeTeam);
        Team away = getTeam(awayTeam);
        
        if (home != null && away != null) {
            home.updateStats(homeGoals, awayGoals);
            away.updateStats(awayGoals, homeGoals);  // 客队的成绩更新反向
        }
    }

    // 排序队伍：按积分，净胜球，进球数
    public void sortTeams() {
        teams.sort((t1, t2) -> {
            if (t2.points != t1.points) {
                return Integer.compare(t2.points, t1.points);  // 先按积分降序
            } else if (t2.goalDifference() != t1.goalDifference()) {
                return Integer.compare(t2.goalDifference(), t1.goalDifference());  // 再按净胜球降序
            } else {
                return Integer.compare(t2.goalsFor, t1.goalsFor);  // 最后按进球数降序
            }
        });
    }

    // 输出所有队伍的积分榜
    public void printLeaderboard() {
        System.out.println("队名           场次 胜 平 负 进球 失球 积分");
        for (Team team : teams) {
            team.printStats();
        }
    }
}

public class FootballLeague {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        League league = new League();
        
        // 示例：添加队伍
        league.addTeam("队伍A");
        league.addTeam("队伍B");
        league.addTeam("队伍C");
        league.addTeam("队伍D");

        // 读取比赛结果并更新数据
        while (true) {
            System.out.println("请输入比赛结果（主队 客队 主队进球 客队进球），输入'结束'结束输入：");
            String input = scanner.nextLine();
            if (input.equals("结束")) {
                break;
            }

            // 格式：主队 客队 主队进球 客队进球
            String[] parts = input.split(" ");
            String homeTeam = parts[0];
            String awayTeam = parts[1];
            int homeGoals = Integer.parseInt(parts[2]);
            int awayGoals = Integer.parseInt(parts[3]);

            // 更新比赛结果
            league.processMatch(homeTeam, awayTeam, homeGoals, awayGoals);
        }

        // 排序并输出排名
        league.sortTeams();
        league.printLeaderboard();
    }
}
